package com.hot100;

import java.util.*;

public class Hash {

    public static void main(String[] args) {

        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(1,100);
        map.put(19,1900);
        map.put(3,300);
        map.put(16,1600);

        Set<Integer> set = map.keySet();
        for (Integer key : set) {
//            System.out.println(map.get(key));
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            System.out.println(entry);
        }

        int[] nums = {2,4,5,3,1,8};
//        Arrays.sort(nums,new Comparator<Integer>());

    }

    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();//<值,下标>
        int[] result = new int[2];
        for (int i = 0; i < nums.length; i++) {
            Integer index = map.get(target - nums[i]);
            if(index!=null)  {
                result[0]=index;
                result[1]=i;
                return result;
            }
            map.put(nums[i],i);
        }
        return null;
    }


    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> map = new HashMap<>();

        return null;
    }


    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        HashSet<Integer> heads = new HashSet<>();

        for (Integer num : set) {
            if(!set.contains(num-1)) {
                heads.add(num);
            }
        }


        int max  = 0;
        int count=0;
        for (Integer head : heads) {
            count=0;
            while(set.contains(head)) {
                count++;
                head=head+1;
            }
            max  =  Math.max(max,count);
        }

        return max;
    }

}
